package com.carrie.mdg.myviewtext.ui;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by mdg on 2017/7/18.
 */

public class MyView extends View {
    private Paint mPaint = new Paint();
    private Path mPath = new Path();

    public MyView(Context context) {
        super(context);
    }

    public MyView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MyView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public MyView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //这类方法一般用于在绘制之前设置底色，或者在绘制之后为界面设置半透明蒙版
//        canvas.drawColor(Color.parseColor("#88880000"));
//        canvas.drawRGB(100, 200, 100);
        canvas.drawARGB(100, 100, 200, 100);
        //-----
//        mPaint.setColor(Color.RED);
//        canvas.drawCircle(200, 200, 100, mPaint);
//
        mPaint.setColor(Color.BLACK);

//        canvas.drawCircle(300, 300, 100, mPaint);
//
//        mPaint.setColor(Color.GREEN);
//        canvas.drawCircle(400, 200, 100, mPaint);

//        mPaint.setStyle(Paint.Style.STROKE);
//        mPaint.setStrokeWidth(20);

        mPaint.setAntiAlias(true);
        mPaint.setStyle(Paint.Style.STROKE);
//        canvas.drawCircle(180, 180, 150, mPaint);

        mPaint.setStyle(Paint.Style.FILL);
//        canvas.drawRect(400, 100, 600, 400, mPaint);

        mPaint.setStrokeWidth(20);
        mPaint.setStrokeCap(Paint.Cap.SQUARE);
        canvas.drawPoint(100, 450, mPaint);

        mPaint.setStrokeCap(Paint.Cap.BUTT);
        canvas.drawPoint(100, 500, mPaint);

        mPaint.setStrokeCap(Paint.Cap.ROUND);
        canvas.drawPoint(100, 400, mPaint);

        float[] points = {0, 0, 700, 100, 700, 150, 800, 100, 800, 150, 800, 200, 800, 250};
        canvas.drawPoints(points, 2, 12, mPaint);

        canvas.drawOval(700, 300, 1000, 400, mPaint);
        canvas.drawLine(100, 600, 900, 700, mPaint);

//        canvas.drawRoundRect(50, 750, 500, 900, 50, 50, mPaint);

//        canvas.drawArc(100, 1000, 500, 1300, -100, 100, true, mPaint);
//        canvas.drawArc(100, 1000, 500, 1300, 20, 140, false, mPaint);

        mPaint.setStyle(Paint.Style.STROKE);
//        canvas.drawArc(100, 1000, 500, 1300, 180, 60, false, mPaint);

        mPaint.setStyle(Paint.Style.FILL);
        mPaint.setColor(Color.RED);

        mPath.addArc(200, 200, 400, 400, -225, 225);
        mPath.arcTo(400, 200, 600, 400, -180, 225, false);
        mPath.lineTo(400, 542);
        canvas.drawPath(mPath, mPaint);




    }
}
